﻿using Splat;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using ReactiveUI;
using Autofac;
using ScienceAIApp.ViewModels;
using ILoggerService = CCLog.ILoggerService;

namespace ScienceAIApp;
public class App
{

    [STAThread]

    static void Main()
    {
        // 依赖注入
        AppIoc.Register();

        // vm can find view
        Locator.CurrentMutable.RegisterViewsForViewModels(Assembly.GetCallingAssembly());

        using var scope = AppIoc.AppContainer.BeginLifetimeScope();

        try
        {
            // 定义Application对象作为整个应用程序入口  

            var app = new Application();

            var win = scope.ResolveOptional<MainWindow>();

            AppEnvironment.Instance.AlertWindow = scope.ResolveOptional<AlertWin>()!;

            app.Run(win);
        }

        // 异常捕获
        catch (Exception e)
        {
            var logger = scope.ResolveOptional<ILoggerService>()!;
            logger.Error(nameof(Main), e);
        }

    }
}
